//
//  RankView.m
//  ZiJinLian
//
//  Created by 🐛 on 2017/4/19.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "RankView.h"

@implementation RankView
-(id)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        self.dic=[NSMutableDictionary dictionary];
    }
    return self;
}
-(void)CancelButtonClicked{
    [_delegate CancelButtonClicked];
}
-(void)creatWithArray:(NSArray *)arry{
    self.sortArray=arry;
    self.array=[NSMutableArray array];
    for (NSDictionary *dic in arry) {
        NSString *string=dic[@"name"];
        [self.array addObject:string];
    }
    
    self.tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, MainW, arry.count*40) style:0];
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    //self.tableView.userInteractionEnabled=NO;
    self.tableView.scrollEnabled=NO;
    [self.tableView setSeparatorColor:SeparatorColor];
    self.tableView.backgroundColor=[UIColor whiteColor];
    [self.tableView registerNib:[UINib nibWithNibName:@"SXTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"SXTableViewCell"];
    [self addSubview:self.tableView];
    self.ShowView=[[UIView alloc]initWithFrame:CGRectMake(0, 40*arry.count, MainW, MainH-40*arry.count)];
    self.ShowView.backgroundColor=[UIColor whiteColor];
    self.ShowView.alpha=0.4;
    [self addSubview:self.ShowView];
    self.CancelBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, MainW, MainH-40*arry.count)];
    [self.CancelBtn addTarget:self action:@selector(CancelButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.ShowView addSubview:self.CancelBtn];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.array.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SXTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"SXTableViewCell"];
    cell.tag=indexPath.row;
    cell.titleLabel.text=[NSString stringWithFormat:@"%@",self.array[indexPath.row]];
    cell.selectionStyle=0;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SXTableViewCell*cell=[tableView cellForRowAtIndexPath:indexPath];
    if (self.lastCell!=cell) {
        cell.titleLabel.textColor=Red_Color;
        cell.image.hidden=NO;
        self.lastCell.titleLabel.textColor=TextColor3;
        self.lastCell.image.hidden=YES;
        self.lastCell=cell;
    }
    self.dic[@"sortType"]=self.sortArray[indexPath.row][@"type"];
    self.dic[@"sortMethod"]=@"dasc";
    [_delegate ChooseButtonClicked:self.dic];
}
@end
